package com.amigo.online.consumer.common.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseConsumerController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.param.dto.video.AreaDto;
import com.amigo.online.consumer.common.service.CommonService;

@RestController
@RequestMapping(value = "/common", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class CommonController extends BaseConsumerController {

	@Autowired
	CommonService commonService;
	
	
	@GetMapping(value = "/global/config")
	public ResponseEntity<Response> getGlobalConfig() {
	     return commonService.getGlobalConfig();
	}
	
	@GetMapping(value = "/global/config/md5")
	public ResponseEntity<Response> getGlobalMd5() {
	     return commonService.getGlobalMd5();
	}
	
	@GetMapping(value = "/area/list/{lang}")
	public ResponseEntity<Response> getAreaList(@PathVariable String lang) {
	     return commonService.getAreaList(lang,0,1,10);
	}
	
	@GetMapping(value = "/area/list/{lang}/{pid}")
	public ResponseEntity<Response> getAreaList(@PathVariable String lang,@PathVariable Integer pid) {
	     return commonService.getAreaList(lang,pid,1,10);
	}
	
	@GetMapping(value = "/area/list/{lang}/{pid}/{page}")
	public ResponseEntity<Response> getAreaList(@PathVariable String lang,@PathVariable Integer pid,@PathVariable Integer page) {
	     return commonService.getAreaList(lang,pid,page,10);
	}
	
	@GetMapping(value = "/area/list/{lang}/{pid}/{page}/{size}")
	public ResponseEntity<Response> getAreaList(@PathVariable String lang,@PathVariable Integer pid,@PathVariable Integer page,@PathVariable Integer size) {
	     return commonService.getAreaList(lang,pid,page,size);
	}
	
	@GetMapping(value = "/area/list/{lang}/{id}")
	public ResponseEntity<Response> getAreaName(@PathVariable String lang,@PathVariable Integer id) {
	     return commonService.getAreaName(lang, id);
	}
	
	
	@PostMapping(value="/linkageQuery")
	public ResponseEntity<Response> linkageQuery(HttpServletRequest request){
		AreaDto dto = (AreaDto) getDto(request,AreaDto.class);
		return commonService.linkageQuery(dto);
	}
	
}
